within BusinessSimulation.Converters.Lookup;

block TableFunctionVector "Table function for vector input and output using Modelica's CombiTable format"
  import BusinessSimulation.Units.*;
  import Modelica.Blocks.Types.{Extrapolation, Smoothness};
  extends Interfaces.PartialConverters.MIMO_nin;
  extends Icons.InterpolationTable;
  parameter Boolean tableOnFile = false "= true, if table is defined on file or in function usertab (combiTable1D.tableOnFile)" annotation(Dialog(group = "TableDataDefinition"));
  parameter Real table[:, :] = fill(0.0, 2, 2) "Table matrix (combiTable1D.table)" annotation(Dialog(group = "TableDataDefinition", enable = not tableOnFile));
  parameter String tableName = "NoName" "Name of the table in the file containing the data" annotation(Dialog(group = "TableDataDefinition", enable = tableOnFile));
  parameter String fileNameURI = modelSettings.lookupDataFileURI "URI of the file to read the data from (default = lookupDataFileURI)" annotation(Dialog(group = "TableDataDefinition", enable = tableOnFile));
  parameter Smoothness smoothness = Smoothness.LinearSegments "Smoothness of table interpolation" annotation(Dialog(group = "TableDataInterpretation"));
  parameter Integer[nin] columns = fill(2, nin) "Columns of table to be interpolated (length must be equal to length of input and output vectors)" annotation(Dialog(group = "TableDataInterpretation"));
  parameter Boolean verboseRead = true "= true, if info message that file is loading is to be printed (combiTable1D.verboseRead)" annotation(Dialog(group = "TableDataDefinition", enable = tableOnFile));
  parameter Extrapolation extrapolation = Extrapolation.LastTwoPoints "Extrapolation of data outside the definition range (combiTable1D.extrapolation)" annotation(Dialog(group = "TableDataInterpretation"));
  parameter Boolean verboseExtrapolation = false "= true, if warning messages are to be printed if table input is outside the definition range (combiTable1D.verboseExtrapolation)" annotation(Dialog(group = "TableDataInterpretation"));
protected
  outer ModelSettings modelSettings;
  parameter String fileName = if tableOnFile then Modelica.Utilities.Files.loadResource(fileNameURI) else "NoName" "Absolute path to the file specified by fileName" annotation(Dialog(group = "Initialization", enable = false));
  Modelica.Blocks.Tables.CombiTable1Dv combiTable1D(smoothness = smoothness, tableOnFile = tableOnFile, tableName = tableName, fileName = fileName, verboseRead = verboseRead, table = table, columns = columns, extrapolation = extrapolation, verboseExtrapolation = verboseExtrapolation) "Modelica combi table" annotation(Placement(visible = true, transformation(origin = {0, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  connect(u, combiTable1D.u) annotation(Line(visible = true, origin = {-91, 0}, points = {{-79, 0}, {79, 0}}, color = {1, 37, 163}));
  connect(combiTable1D.y, y) annotation(Line(visible = true, origin = {85.5, 0}, points = {{-74.5, 0}, {74.5, 0}}, color = {1, 37, 163}));
  // assert statements
  assert(size(columns, 1) == nin, "Columns vector does not match length of input vector");
  // assert(min(columns) >= 2 and max(columns) <= size(table, 2), "Columns are out of range");
  annotation(Documentation(info = "<html>
<p class=\"aside\">This information is part of the Business Simulation&nbsp;Library (BSL). Please support this work and <a href=\"https://www.paypal.com/donate/?hosted_button_id=GXVZT8LD7CFXN\" style=\"font-weight:bold; color:orange; text-decoration:none;\">&#9658;&nbsp;donate</a>.</p>
<p>This converter uses the Modelica CombiTable format to read in a 1-D table function from file. For more explanation regarding the 1-D Modelica CombiTable interpolation see <a href=\"modelica:/Modelica.Blocks.Tables.CombiTable1Dv\">Modelica.Blocks.Tables.CombiTable1Dv</a>.</p>
<h4>Notes</h4>
<p>The Modelica CombiTable format can be generated by Wolfram Mathematica using <code>Export[]:</code></p>
<p><code>Export[ <em>filename</em>, { {\"TableName1\", table1}, {\"TableName2\", table2}, ... }, \"MCTT\" ]</code></p>
<p>where <code>table1, table2, ...</code> are 2-dimensional arrays. By default all lookup data are assumed to be included in a single file whose name is given by the global parameter <code>lookupDataFileURI</code>.</p>
<h4>See also</h4>
<p><a href=\"modelica://BusinessSimulation.Converters.Lookup.TableFunction\">TableFunction</a>,&nbsp;<a href=\"modelica://BusinessSimulation.InformationSources.LinearTimeTable\">LinearTimeTable</a></p></html>", revisions = "<html>
<ul>
<li>Class adapted to compliance with MSL 4.0.0 in v2.2.</li><br>
</ul>
</html>"), Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10})), Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5})));
end TableFunctionVector;
